<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="test"></div>
  
  <!-- 引入react核心库 -->
  <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <!-- 用于支持react操作DOM -->
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <!-- 用于将jsx转为js -->
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  
  <script type="text/babel">
    class Demo extends React.Component{
      /**
       * React.createRef 调用后可以返回一个容器，该容器可以存储被ref所标识的节点
       * 该容器是“专人专用”的
      */
      myRef=React.createRef();
      myRef1=React.createRef();
      
      showData1=()=>{
        alert(this.myRef.current.value);
      }

      showData2=()=>{
        alert(this.myRef1.current.value);
      }

      render(){
        return (
          <div>
            <input ref={this.myRef} type="text" placeholder='点击按钮提示数据'/>&nbsp;
            <button onClick={this.showData1}>点击按钮提示左侧数据</button>&nbsp;
            <input ref={this.myRef1} onBlur={this.showData2} type="text" placeholder='失去焦点提示数据'/>
          </div>
        )
      }
    }

    ReactDOM.render(<Demo/>,document.getElementById('test'))
  </script>
</body>
</html>